<template>
    <div class="app-container">
<!--        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
<!--            <el-form-item label="分配时间" prop="assignTime">-->
<!--                <el-date-picker clearable-->
<!--                                v-model="queryParams.assignTime"-->
<!--                                type="date"-->
<!--                                value-format="yyyy-MM-dd"-->
<!--                                placeholder="请选择分配时间">-->
<!--                </el-date-picker>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="文件类型" prop="fileType">-->
<!--                <el-select v-model="queryParams.fileType" placeholder="请选择文件类型" clearable>-->
<!--                    <el-option-->
<!--                        v-for="dict in dict.type.dcc_file_type"-->
<!--                        :key="dict.value"-->
<!--                        :label="dict.label"-->
<!--                        :value="dict.value"-->
<!--                    />-->
<!--                </el-select>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="紧急程度" prop="level">-->
<!--                <el-select v-model="queryParams.level" placeholder="请选择紧急程度" clearable>-->
<!--                    <el-option-->
<!--                        v-for="dict in dict.type.dcc_emergency_level"-->
<!--                        :key="dict.value"-->
<!--                        :label="dict.label"-->
<!--                        :value="dict.value"-->
<!--                    />-->
<!--                </el-select>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="到期时间" prop="dueDate">-->
<!--                <el-date-picker clearable-->
<!--                                v-model="queryParams.dueDate"-->
<!--                                type="date"-->
<!--                                value-format="yyyy-MM-dd"-->
<!--                                placeholder="请选择到期时间">-->
<!--                </el-date-picker>-->
<!--            </el-form-item>-->
<!--            <el-form-item>-->
<!--                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--            </el-form-item>-->
<!--        </el-form>-->
        <el-table v-loading="loading" :data="assignList" @selection-change="handleSelectionChange">
            <el-table-column label="ID" align="center" prop="id" />
            <el-table-column label="文件名称" align="center" prop="fileName" />
            <el-table-column label="分配时间" align="center" prop="assignTime" width="100">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.assignTime, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="文件类型" align="center" prop="fileType">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.dcc_file_type" :value="scope.row.fileType"/>
                </template>
            </el-table-column>
            <el-table-column label="紧急程度" align="center" prop="level">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.dcc_emergency_level" :value="scope.row.level"/>
                </template>
            </el-table-column>
            <el-table-column label="到期时间" align="center" prop="dueDate" width="100">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.dueDate, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="发送人" align="center" prop="senderName" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="100">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="创建人" align="center" prop="createBy" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-tickets"
                        @click="openDetails(scope.row)"
                    >阅览状态</el-button>

                </template>
            </el-table-column>
        </el-table>

        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        />
        <!--  -->
        <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
            <file-assign-record :file-assign-id="fileAssignId" v-if="open"/>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="cancel">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { listAssign} from "@/api/business/assign";
import FileAssignRecord from "@/views/business/dcc/fileAssignRecord.vue";
export default {
    name: "fileAssign",
    components: {FileAssignRecord},
    dicts: ['dcc_file_type', 'dcc_emergency_level'],
    props: {
        fileId: {
            type: String
        }
    },
    data() {
        return {
            fileAssignId: "",
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 文件分配表格数据
            assignList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                fileName: null,
                assignTime: null,
                fileType: null,
                level: null,
                dueDate: null,
            },
            // 表单参数
            form: {},
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询文件分配列表 */
        getList() {
            this.queryParams.fileId = this.fileId;
            this.loading = true;
            listAssign(this.queryParams).then(response => {
                this.assignList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
        },
        openDetails(item){
            this.fileAssignId = item.id
            this.open = true;
            this.title = "Details"
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                fileId: null,
                fileName: null,
                filePath: null,
                assignTime: null,
                fileType: null,
                viewPermit: null,
                level: null,
                dueDate: null,
                sender: null,
                createTime: null,
                createBy: null,
                updateTime: null,
                updateBy: null,
                remark: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length!==1
            this.multiple = !selection.length
        },
        // /** 新增按钮操作 */
        // handleAdd() {
        //     this.reset();
        //     this.open = true;
        //     this.title = "添加文件分配";
        // },
        // /** 修改按钮操作 */
        // handleUpdate(row) {
        //     this.reset();
        //     const id = row.id || this.ids
        //     getAssign(id).then(response => {
        //         this.form = response.data;
        //         this.open = true;
        //         this.title = "修改文件分配";
        //     });
        // },
        // /** 提交按钮 */
        // submitForm() {
        //     this.$refs["form"].validate(valid => {
        //         if (valid) {
        //             if (this.form.id != null) {
        //                 updateAssign(this.form).then(response => {
        //                     this.$modal.msgSuccess("修改成功");
        //                     this.open = false;
        //                     this.getList();
        //                 });
        //             } else {
        //                 addAssign(this.form).then(response => {
        //                     this.$modal.msgSuccess("新增成功");
        //                     this.open = false;
        //                     this.getList();
        //                 });
        //             }
        //         }
        //     });
        // },
        // /** 删除按钮操作 */
        // handleDelete(row) {
        //     const ids = row.id || this.ids;
        //     this.$modal.confirm('是否确认删除文件分配编号为"' + ids + '"的数据项？').then(function() {
        //         return delAssign(ids);
        //     }).then(() => {
        //         this.getList();
        //         this.$modal.msgSuccess("删除成功");
        //     }).catch(() => {});
        // },
        // /** 导出按钮操作 */
        // handleExport() {
        //     this.download('system/assign/export', {
        //         ...this.queryParams
        //     }, `assign_${new Date().getTime()}.xlsx`)
        // }
    }
};
</script>
